#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long T,n,a[N],mx;


void dfs(long long p,long long q0,long long q1,long long co,long long ans){
    if(p>n){
        mx = max(mx,ans);
        return ;
    }
   dfs(p+1,p,q1,0,ans + (a[p]==a[q0])*a[p]);
   dfs(p+1,q1,p,1,ans + (a[p]==a[q1])*a[p]);
}
void solve(){
    mx = 0;
    scanf("%lld",&n);
    for(int i = 1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    dfs(1,0,0,0,0);
    dfs(1,0,0,1,0);
    printf("%lld\n",mx);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%lld",&T);
    while(T--){
        solve();
    }
    return 0;
}
